package game.level.tiles;

import game.gfx.SpriteSheet;

public class AnimatedTile extends Tile 
{
	private int[][] animationCoords;
	private int currentAnimationIndex;
	private long lastIterationTime;
	private int animationSwitchDelay;
	
		
	public AnimatedTile(int id, SpriteSheet sheet, int[][] animationCoords, int animationSwitchDelay)
	{
		super(id, sheet, animationCoords[0][0], animationCoords[0][1], false);
		
		this.animationCoords = animationCoords;
		this.currentAnimationIndex = 0;
		this.lastIterationTime = System.currentTimeMillis();
		this.animationSwitchDelay = animationSwitchDelay;	
	}
	
	public void tick()
	{
		if ((System.currentTimeMillis() - lastIterationTime) >= animationSwitchDelay)
		{
			lastIterationTime = System.currentTimeMillis();
			
			if ((currentAnimationIndex + 1) < animationCoords.length) currentAnimationIndex++;
			else currentAnimationIndex = 0;

			this.x = animationCoords[currentAnimationIndex][0];
			this.y = animationCoords[currentAnimationIndex][1];
		}
	}
}
